//
//  BasicViewController.m
//  HuaShun
//
//  Created by Fuhao on 16/8/7.
//  Copyright © 2016年 Phenix. All rights reserved.
//

#import "BasicViewController.h"

//#import "HAZTabBarVC.h"
//#import "HomePageVC.h"
//#import "LoginVC.h"
#import "MTLoginHomeVC.h"
@interface BasicViewController ()
@property(nonatomic,strong) MJRefreshNormalHeader *headerRefresh;
@property(nonatomic,strong) MJRefreshAutoNormalFooter *footerRefresh;

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *img;
@end

@implementation BasicViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = KBackColor;
    self.page = 1;
    [self initVariable];
    [self initUI];
    
    [self CreateNav];
}
-(void)initVariable
{
    
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
//    self.tableView.frame = self.view.bounds;
}
-(void)initUI{
    
}
-(void)loadData{
    DLog(@"请求");
    if (self.headerRefresh) {
        [self.headerRefresh endRefreshing];
    }
    if (self.footerRefresh) {
        [self.footerRefresh endRefreshing];
    }
}

-(void)setupTableView:(UITableViewStyle)style header:(BOOL)header footer:(BOOL)footer{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavHeight, self.view.width, self.view.height)  style:style];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    [self.view addSubview:self.tableView];
    
    MJWeakSelf;
    if (header) {
        self.headerRefresh = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            weakSelf.page = 1;
            [weakSelf loadData];
        }];
        self.tableView.mj_header = self.headerRefresh;
    }
    if (footer) {
        self.footerRefresh = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            weakSelf.page++;
            [weakSelf loadData];
        }];
        self.tableView.mj_footer = self.footerRefresh;
    }
}
#pragma mark - tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [[UITableViewCell alloc] init];
}










#pragma mark - 缺省页
-(void)createViewBynoMsgName:(NSString *)msgName alertMsg:(NSString *)alertMsg{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(225)+NavHeight);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(32));
        make.height.equalTo(@(32));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_16;
    label.textColor = TextTiTleColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
     }];
}





-(void)createHomeViewBynoMsgName:(NSString *)msgName alertMsg:(NSString *)alertMsg{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(125)+36);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(63));
        make.height.equalTo(@(63));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_14;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
    }];
}

#pragma mark - 缺省页
-(void)createViewBynoMsgName2:(NSString *)msgName alertMsg:(NSString *)alertMsg alertMsg2:(NSString *)alertMsg2  height:(NSInteger )height{
    self.noMsgView2 = [[UIView alloc] initWithFrame:CGRectMake(0, height, kScreenWidth, kScreenHeight-height)];
    self.noMsgView2.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView2 addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.noMsgView2.mas_top).with.offset(kFit(50)+36);
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(0));
        make.height.equalTo(@(0));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_15;
    label.textColor = TextTiTleColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    [self.noMsgView2 addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(kFit(150));
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(kFit(350)));
     }];
    UILabel *label2 = [[UILabel alloc] init];
    label2.font = Font_13;
    label2.textColor = KRedColor;
    label2.textAlignment = NSTextAlignmentCenter;
    label2.text = alertMsg2;
    [self.noMsgView2 addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(kFit(350)));
        make.height.equalTo(@15);
    }];
}


-(void)createHomeViewBynoMsgName3:(NSString *)msgName alertMsg:(NSString *)alertMsg{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 280, kScreenWidth, kScreenHeight-280)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(80)+36);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(63));
        make.height.equalTo(@(63));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_14;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
    }];
}


-(void)createHomeViewBynoMsgName:(NSString *)msgName alertMsg:(NSString *)alertMsg withSize:(CGSize)size{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(125)+36);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.mas_equalTo(size.width);
        make.height.mas_equalTo(size.height);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_14;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
    }];
}



- (void)dealloc{
    DLog(@"%s",__func__);
}




 


 


/*!
 *  当前登录账号在其它设备登录时会接收到该回调
 */
- (void)userAccountDidLoginFromOtherDevice {
    
}

/*!
 *  当前登录账号已经被从服务器端删除时会收到该回调
 */
- (void)userAccountDidRemoveFromServer {
    
}



-(void)CreateNav
{
    //默认返回事件
    //默认返回事件
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc ]initWithImage:[UIImage imageWithOriginalName:@"返回黑色"] style:UIBarButtonItemStyleDone target:self action:@selector(returnAction)];
    self.navigationItem.leftBarButtonItem = leftBtn;
}
- (void)returnAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)logintoHome {
//    UIWindow * window = [[UIWindow alloc] init];
//    BasicNavigationController * nav= [[BasicNavigationController alloc] initWithRootViewController:[[HomePageVC alloc] init]];
//    window.rootViewController = nav;
//    self.window = window;
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:KMainColor] forBarPosition:UIBarPositionAny
//                                                     barMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
//    self.navigationController.navigationBar.barTintColor = KMainColor;
//    [self.window makeKeyAndVisible];
}

- (void)logouTotLogin {
    UIWindow * window = [[UIWindow alloc] init];
    BasicNavigationController *nav = [[BasicNavigationController alloc]initWithRootViewController:GetViewControllerInStoryboard(@"Login", @"MTLoginHomeVC")];
    [self.window setRootViewController:nav];
    
    window.rootViewController = nav;
    self.window = window;
    [self.window makeKeyAndVisible];
}
@end
